package com.xinxin.blockchain.asset.strategy;

import com.xinxin.blockchain.model.AccountAsset;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 资产增加
 * 可用 增加
 * 冻结 不变
 * 总额 增加
 *
 * @author ys
 * @date 2021/5/24
 */
@Component
public class AssetAddOperateStrategy extends AssetOperateStrategy {

    @Override
    public boolean operate(AccountAsset asset, BigDecimal amount) {
        AccountAsset update = new AccountAsset()
                .setId(asset.getId())
                .setVersion(asset.getVersion())
                .setAvailable(asset.getAvailable().add(amount))
                .setTotal(asset.getTotal().add(amount));
        return accountAssetService.optimisticLockUpdate(update);
    }
}
